package com.cc.learning.controller;

import com.fesine.commons.util.CheckCodeCreateUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by Administrator on 2017/4/7.

    生成验证码保存到session
 */
@Controller
@RequestMapping("/images")
public class CaptchaImageCreateController {
    private  static  final Logger LOGGER = Logger.getLogger(CaptchaImageCreateController.class);

    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession(true);
        String token = CheckCodeCreateUtil.createCode(response);
        session.setAttribute("captchaToken",token);

        LOGGER.info("SessionID  ="+session.getId()+"token ="+token);
    }
}
